#pragma once
#ifndef myEventManager_h__
#define myEventManager_h__

#include "../inc/sky.h"
#include "./myMessage.h"
#include "../inc/skyTimer.h"
#include "../inc/skyInput.h"

namespace Sky
{
	class Timer;
}
namespace Sky
{
	using namespace Sky;
	
	class myMsgMgr;
	class myApplet;
	
	typedef TResult  (*EventCalledProc)(myMsgMgr* ,Msg* );
	
	class myMsgMgr : public TreeNode
	{
		DECL_RTTI1(myMsgMgr,TreeNode);
	protected:
		Handler::Delegate 		m_CallBack;
		FifoQueue<Msg*,10>	m_EventQueue;
		typedef struct _CallbackNode_
		{
			Handler::Delegate _cb;
			u32 _interal;
			u32 _left;
			Bool _bRepeat;
		}CallbackNode;
		typedef List<CallbackNode> CBList;
		CBList _list;
		Timer* _Timer;
		Input _input;
	public:
		myMsgMgr();
		~myMsgMgr();
		virtual MsgStatus	handlePostEvent(Msg* msg){m_EventQueue.in(msg);return vContinue;};
		virtual MsgStatus 	handleSendEvent(Msg* msg){return vContinue;};
		//
		virtual Bool		getQueuedMessage(Msg* msg);
		Input&				getInput(){return _input;}
		Timer& 				getTimer();
		Void				handleTimer();
		Void				deleteTimer(Handler::Delegate cb);
		Bool				createTimer(Handler::Delegate cb,u32 internal,Bool bRepeat = vTrue);
		Void				setEventCallBack(Handler::Delegate proc){m_CallBack = proc;}
		virtual myApplet*	getApplication();;
		TResult				dispatchSendEvent( Msg* msg );
		MsgStatus			callSystem(Msg* message);
	
	};
}

#endif // myIEventManager_h__
